<div id="admin-content">
	<h3>Quản lý sản phẩm</h3>
	<div id="body">
	<?php
		if(isset($this->thongbao)){
			echo '<div class="alert alert-success alert-dismissable">';
			echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>';
			echo $this->thongbao;
			echo '</div>';
		}

		if(isset($this->products))
			$products = $this->products;

		$lnkAdd = $this->url('admin',
					array(
							'controller'=>'manage',
							'action'=>'add'
					));
		$lnkAdd = '<a class="btn btn-primary" href="' . $lnkAdd . '">Thêm sản phẩm</a>';
		echo $lnkAdd;
	?>
	<form>	
	<table id="data" class="table">
		<thead>
			<tr>
				<td></td>
				<td>STT</td>
				<td>Mã hàng</td>
				<td style="width:240px;">Hình ảnh</td>
				<td>Số lượng</td>
				<td>Ngày nhập</td>
				<td>Đơn giá</td>	
				<td>Thao tác</td>
			</tr>
		</thead>
		<tbody>
			<?php
			if(count($products)>0){
				$counter = 1;
				foreach ($products as $product) {
					$lnkEdit = $this->url('admin',
											array(
												 'controller'=>'manage',
												 'action'=>'edit',
												 'id' => $product->id
											));
					$lnkEdit = '<a style="margin-top:3px;"class="btn btn-primary" href="' . $lnkEdit . '">Sửa</a>';

					$lnkDelete 	= $this->url('admin',
									array(
											'controller'=>'manage',
											'action'=>'delete',
											'id' => $product->id
									));
					$lnkDelete = '<a style="margin-top:3px;"class="btn btn-danger" href="' . $lnkDelete . '">Xóa</a>';

					$lnkCreateBill = $this->url('admin',
					                            array(
												 'controller'=>'bill',
												 'action'=>'create-bill',
												 'id' => $product->id
											));
					$lnkCreateBill = '<a style="margin-top:3px;"class="btn btn-success" href="' . $lnkCreateBill . '">Tạo hóa đơn</a>';
					$str = '';
					$str .= '<tr>';
					$str .= '<td><input type="checkbox" value="'.$product->id.'"></td>';
					$str .= '<td>'.$counter.'</td>';
					$linkDetail = $this->url('admin',
					                         array('controller'=>'manage','action'=>'view-detail','id'=>$product->id
					                               ));
					$linkDetail = '<a href="'.$linkDetail.'">'.$product->maHang.'</a>';
					$str .= '<td class="txtCenter">' . $linkDetail . '</td>';
					$str .= '<td>';
					$imgArr = explode('|', $product->hinhAnh);
					$patch = '/files/'.$product->loaiHang.'/'.$product->maHang.'/';
					for($i = 0; $i < count($imgArr)-1; $i++){
						if($i < 2)
						$str .= '<img class="img-thumbnail" src="'.$patch.$imgArr[$i].'" id="thumbnail-images" onerror="imgError(this)">';	
					}
					$str .= '</td>';
					$str .= '<td class="txtCenter">' . $product->soLuong .'/'.$product->soLuongNhapVao .'</td>';
					// $str .= '<td class="txtCenter">' . $product->soLuongNhapVao . '</td>';
					$str .= '<td class="txtCenter">' . $product->ngayNhap . '</td>';
					$loaiHang = "Giày";
					if($product->loaiHang>1)
						$loaiHang = "Túi xách";
					//$str .= '<td class="txtCenter">' . $loaiHang . '</td>';
					$str .= '<td class="txtCenter">' . $product->gia . '</td>';
					$str .= '<td class="txtCenter">' . $lnkEdit . '&nbsp' . $lnkDelete .'<br/>' . $lnkCreateBill .'</td>';

					$str .= '</tr>';
					echo $str;
					$counter++;
				}
			}
			?>
		</tbody>
	</table>
	<div class="edit">
		<button class="btn btn-success" type="submit">Update</button> &nbsp;
		<button class="btn btn-danger" type="submit">Delete</button>
	</div>
	</form>
	</div>
</div>